package cn.aticow.springboot.bean;

/*import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;*/

import com.alibaba.fastjson.JSONObject;

import java.text.SimpleDateFormat;

public class TestJsonComplex {
    public static void main(String[] args){
        //稍微复杂的包装类，转换为json类型的字符串
        AgvFeedBack feedBack = new AgvFeedBack();
        Task task=new Task();
        feedBack.setIntendedVehicle("Vehicle-0001");
        feedBack.setTaskNo("v1order");
        feedBack.setTaskState("LOAD_COMPLETED");
        task.setId(12);
        task.setTask_No("v234");
        //转换日期格式
        /*DateFormat simpleDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String d=simpleDate.format(new Date());
        Date date=simpleDate.parse(d);
        */
        /*task.setFinishTime(new Date());
        feedBack.setTask(task);
        Gson gson=new Gson();
        String json=gson.toJson(feedBack);
        System.out.println(json);*/
        //将json类型的字符串，转换为对象
        String jsonString="{'intendedVehicle':'Vehicle-0002','taskNo':'Order0001','taskState':'FINISHED','task':{'id':'215140703','task_No':'taskNumber0001'," +
                "'finishTime':'2011-12-01 13:24:36'}}";
        JSONObject JsonObject= JSONObject.parseObject(jsonString);
        AgvFeedBack agv=JsonObject.toJavaObject(JsonObject,AgvFeedBack.class);
        System.out.println(agv.getIntendedVehicle());
        System.out.println(agv.getTask().getId());
        //转换日期格式
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate=simpleDateFormat.format(agv.getTask().getFinishTime());
        System.out.println(strDate);
    }
}
